package com.shu.thread;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2020/8/25 16:19
 */

public class Test3 {
    Queue<String> buffer = new LinkedList<String>();

    public void give(String data) {
        synchronized (this) {
            buffer.add(data);
            notify();
        }
    }

    public String take() throws InterruptedException {
        synchronized (this) {

            // 避免被虚假唤醒
            while (buffer.isEmpty()) {
                wait();
            }
            return buffer.remove();
        }
    }



}
